/*
 * RunModules.java
 * 
 * Allows the runing of all the diferent methods in the program
 * 
 * Author: Andres Ruiz
 * License: see License.txt
 */
import java.util.Scanner;

public class RunModules
{
	Scanner c = new Scanner(System.in);
	PeriodicTableAcess searchEng;
	MoleCalculator moleCalc;
	MolecularFormula molecularFormula;
	int menuSel = 0;

	public void Search()
	{
		System.out.println("Press 1 to search by atomic number");
		System.out.println("Press 2 to search by Element Name or Symbol");
		int a = c.nextInt();
		switch (a)
		{
			case 1:
				SearchNum();
				break;
			case 2:
				SearchEngine();
				break;
			default:
				SearchEngine();
				break;
		}
	}
	private void periodicDebug()// Debug Method
	{
		for (int i = 0; i < 118; i++)// Prints all of the elements and their
										// info
		{
			searchEng = new PeriodicTableAcess(i + 1);
			searchEng.PrintSearch();
			System.out.println();
		}
	}
	public void SearchNum()
	{
		int searchArg;
		System.out.println("Please type the desired element you would like to lookup:");
		System.out.println("You can search for the Element's Atomic Number.");
		searchArg = c.nextInt();
		searchEng = new PeriodicTableAcess(searchArg);
		searchEng.PrintSearch();
		System.out.println();
		System.out.println("Search for another?");
		System.out.println("Y/N ?");
		String Answer = c.next();
		if (!Answer.equalsIgnoreCase("N"))
			SearchNum();
	}
	public void SearchEngine()
	{
		String searchArg;
		System.out.println("Please type the desired element you would like to lookup:");
		System.out.println("You can search for the Element's Name or Symbol.");
		searchArg = c.next();
		searchEng = new PeriodicTableAcess(searchArg);
		searchEng.PrintSearch();
		System.out.println("\nSearch for another?");
		System.out.println("Y/N ?");
		String Answer = c.next();
		if (!Answer.equalsIgnoreCase("N"))
			SearchEngine();
	}

	public void MoleCalculator()
	{
		String ele;
		double atomicMass;
		double mass;
		System.out.println("Please type the element you are trying to calculate:");
		System.out.println("You can either write the element name or symbol");
		ele = c.next();
		System.out.println("Please type the grams of you have:");
		mass = c.nextDouble();

		moleCalc = new MoleCalculator(mass, ele);

		moleCalc.PrintResults();
		System.out.println("Preform another calculation?");
		System.out.println("Y/N");
		String Answer = c.next();
		if (!Answer.equalsIgnoreCase("N"))
			MoleCalculator();
	}

	public void EmpiricalCalc()
	{
		double[] Moles;
		String[] Elements;
		int eleInCompound;
		System.out.println("For this calculator to work you first need to know the amount of moles");
		System.out.println("for each compound. This can be done in menu option 2");
		System.out.print("How many elements are in the compound: ");
		eleInCompound = c.nextInt();

		Moles = new double[eleInCompound];
		Elements = new String[eleInCompound];

		for (int i = 0; i < Elements.length; i++)
		{
			System.out.print("Please type the element's name:");
			Elements[i] = c.next();
			System.out.println("Please type the amount of moles in the compound:");
			Moles[i] = c.nextDouble();
		}

		System.out.println("Please wait while the information is processed...");

		EmpiricalFormula EmpiricCalc = new EmpiricalFormula(Moles, Elements);
		EmpiricCalc.printResults();
		System.out.println("Preform another calculation?");
		System.out.println("Y/N");
		String Answer = c.next();
		if (!Answer.equalsIgnoreCase("N"))
			EmpiricalCalc();
	}

	public void MolecularFormula()
	{
		int elementCount;
		String[] elements;
		int[] numofelement;
		double molarMass;

		System.out.println("Please type the amount of elements in the empirical formula:");
		elementCount = c.nextInt();

		elements = new String[elementCount];
		numofelement = new int[elementCount];

		for (int i = 0; i < elementCount; i++)
		{
			System.out.println("Please type the element name or symbol");
			elements[i] = c.next();
			System.out.println("Please type the element's subscrit");
			numofelement[i] = c.nextInt();
		}

		System.out.println("Please type the molar mass of the final compound");
		molarMass = c.nextDouble();

		molecularFormula = new MolecularFormula(elements, numofelement, molarMass);
		molecularFormula.printResult();

		System.out.println("Preform another calculation?");
		System.out.println("Y/N");
		String Answer = c.next();
		if (!Answer.equalsIgnoreCase("N"))
			MolecularFormula();
	}
}
